package com.aliyun.commons.model;

import java.io.Serializable;

import lombok.Data;

/**
 * 结果
 *
 * 
 * @date 2024/11/27
 */
@Data
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 6617379650075869748L;

    private T data;
    private String code;
    private String message;
    private boolean success;

    /**
     * 成功
     *
     * @param data 数据
     * @return {@link Result }<{@link T }>
     */
    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setData(data);
        result.setSuccess(true);
        return result;
    }

    /**
     * 失败
     *
     * @param code    法典
     * @param message 消息
     * @return {@link Result }<{@link T }>
     */
    public static <T> Result<T> fail(String code, String message) {
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        result.setSuccess(false);
        return result;
    }
}